﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Poco;
using Metier;

namespace WebApp.Controllers
{
    [Authorize(Roles="Manager")]
    public class RessourcesController : Controller
    {
        // GET: /Ressources/
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult listeServeur(string nomRestaurant)
        {
            GestionServeur serveur_manager = new GestionServeur();

            List<Serveur> serveurs = new List<Serveur>();

            if (nomRestaurant != null)
            {
                serveurs = serveur_manager.Lister();
            }
            else
            {
                serveurs = serveur_manager.Lister();
            }

            return View(serveurs);
        }

        // GET: /Ressources/Details/5
        public ActionResult DetailServeur(int id)
        {
            GestionServeur serv = new GestionServeur();
            
            return View(serv.Chercher(id));
        }

        // GET: /Ressources/Create
        public ActionResult CreateServeur()
        {
            Serveur serveur = new Serveur();

            return View(serveur);
        } 

        // POST: /Ressources/Create
        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        // GET: /Ressources/Edit/5
        public ActionResult EditServeur(int id)
        {
            GestionServeur serv = new GestionServeur();
            
            return View(serv.Chercher(id));
        }

        // POST: /Ressources/Edit/5
        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        // GET: /Ressources/Delete/5
        public ActionResult DeleteServeur(int id)
        {
            GestionServeur serv = new GestionServeur();
            serv.Supprimer(serv.Chercher(id));
            return View(serv);
        }
    }
}
